package com.ycode.bang.anbang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.model.TroubleTyoe;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by maosongsong on 2016/4/12.
 */
public class SelectAdapter extends ArrayAdapter<TroubleTyoe> {
    private LayoutInflater layoutInflater;
    private List<TroubleTyoe> list;
    public Context context;

    public SelectAdapter(Context context, List<TroubleTyoe> list) {
        super(context, 0, list);
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.list_item_select, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(list.get(position).getAlias());
        return convertView;
    }


    static class ViewHolder {
        @InjectView(R.id.text)
        TextView text;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }


    }

    @Override
    public int getCount() {
        return list.size();
    }
}
